import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { BindAclDto } from './dto/bind.acl.dto';
import { createRoleDto } from './dto/create.role.dto';
import { RoleListDto } from './dto/role.list.dto';
import { RoleService } from './role.service';

@ApiTags('后台管理系统-角色管理')
@Controller('role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}
  /**
   * @Author: laotongshu
   * @Date: 2022-10-10 10:54:43
   * @LastEditors: laotongshu
   * @Description: 创建角色
   * @param {Object} {}
   * @return {*}
   */
  @ApiOperation({ summary: '创建角色' })
  @Post()
  async createRole(@Body() createRoleDto: createRoleDto): Promise<string> {
    return await this.roleService.createRole(createRoleDto);
  }

  @ApiOperation({ summary: '查询权限列表' })
  @Get()
  async getRole(@Query() roleDto: RoleListDto) {
    return await this.roleService.getRole(roleDto);
  }

  /**
   * @Author: laotongshu
   * @Date: 2022-10-10 17:02:36
   * @LastEditors: laotongshu
   * @Description: 给角色绑定权限
   * @param id: 角色id
   * @return {*}
   */
  @ApiOperation({ summary: '给角色绑定权限' })
  @Post('/bind/:id')
  async bindAccess(@Param('id') id: string, @Body() bindAclDto: BindAclDto) {
    return await this.roleService.bindAccess(id, bindAclDto);
  }
}
